package com.ruoyi.xysl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xysl.api.domain.XyslGarden;
import com.ruoyi.xysl.service.ISysXyslGardenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 学校园区Controller
 *
 * @author xysl
 * @date 2025-01-17
 */
@RestController
@RequestMapping("/garden")
public class SysXyslGardenController extends BaseController
{
    @Autowired
    private ISysXyslGardenService xyslGardenService;

    /**
     * 查询学校园区列表
     */
    @RequiresPermissions("enroll:garden:list")
    @GetMapping("/list")
    public TableDataInfo list(XyslGarden xyslGarden)
    {
        startPage();
        List<XyslGarden> list = xyslGardenService.selectXyslGardenList(xyslGarden);
        return getDataTable(list);
    }



    /**
     * 导出学校园区列表
     */
    @RequiresPermissions("enroll:garden:export")
    @Log(title = "学校园区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XyslGarden xyslGarden)
    {
        List<XyslGarden> list = xyslGardenService.selectXyslGardenList(xyslGarden);
        ExcelUtil<XyslGarden> util = new ExcelUtil<XyslGarden>(XyslGarden.class);
        util.exportExcel(response, list, "学校园区数据");
    }

    /**
     * 获取学校园区详细信息
     */
    @RequiresPermissions("enroll:garden:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(xyslGardenService.selectXyslGardenById(id));
    }

    /**
     * 新增学校园区
     */
    @RequiresPermissions("enroll:garden:add")
    @Log(title = "学校园区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XyslGarden xyslGarden)
    {
        return toAjax(xyslGardenService.insertXyslGarden(xyslGarden));
    }

    /**
     * 修改学校园区
     */
    @RequiresPermissions("enroll:garden:edit")
    @Log(title = "学校园区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XyslGarden xyslGarden)
    {
        return toAjax(xyslGardenService.updateXyslGarden(xyslGarden));
    }

    /**
     * 删除学校园区
     */
    @RequiresPermissions("enroll:garden:remove")
    @Log(title = "学校园区", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xyslGardenService.deleteXyslGardenByIds(ids));
    }
}
